var G_SE=new Array();
G_SE['1']={classname:'ico ico_kk',action:'http://search.xunlei.com/search.php',kname:'keyword',title:'迅雷搜索'};
G_SE['2']={classname:'ico ico_bd',action:'http://www.baidu.com/s',kname:'wd',title:'百度搜索'};
G_SE['3']={classname:'ico ico_gg',action:'http://www.google.com/search',kname:'q',title:'谷歌搜索'};
var g_curre_se=2;
var G_USE_KANKAN_SEARCH=false;
function choose_se(num){
	if(num==1||num==2||num==3){
		try{
			$g('b_curr_se').className=G_SE[num].classname;
			$g('curr_se').title=G_SE[num].title;
			
			$g('zonghe_search').action=G_SE[num].action;
			$g("keyword").name=G_SE[num].kname;
			
			setCookieWithDomain('xl7_d_se',num,24*30,'123.xunlei.com');
			$g('lab_list').style.display='none';			
			if(num==1){
				if($g("keyword").value==''||!G_USE_KANKAN_SEARCH){
					setSearchInputContent($g("keyword"));
					G_USE_KANKAN_SEARCH=true;
				}
			}else{
				stopSearchTextTimer();
				G_USE_KANKAN_SEARCH=false;
				$g('keyword').value='';
			}		
		}catch(e){}
		g_curre_se=num;
	}
}
function search_check(){
	var a=$g("keyword").value;	
	a=strip_tags(a.Trim());	
	a=a.replace(/(\/)|(\\)|(\")|(\')/g,"");	
	if(a=="\u641c\u7d22\u8d85\u8fc710\u4e07\u90e8\u5f71\u89c6\u5185\u5bb9"||a==""){
		$g("keyword").value="";
		$g("keyword").focus();
		if(g_curre_se==1){	
			window.open("http://www.xunlei.com/?id=4120");	
		}else if(g_curre_se==2){
			window.open("http://www.baidu.com");	
		}else if(g_curre_se==3){
			window.open("http://www.google.com");	
		}
		return false;
	}
	return true;
}
String.prototype.Trim=function(){
	var p=/(^\s*)|(\s*$)/g;
	return this.replace(p,'');
}
function strip_tags(a){
	if(arguments.length<3)a=a.replace(/<\/?(?!\!)[^>]*>/gi,"");
	else{
		var b=arguments[1],c=eval("["+arguments[2]+"]");
		b=b?"</?(?!("+c.join("|")+"))\u0008[^>]*>":"</?("+c.join("|")+")\u0008[^>]*>";
		a=a.replace(RegExp(b,"gi"),"")
	}
	return a;
}
function show_se(){
	$g('lab_list').style.display='block';
}
function stopstimer(name){
	try{
		 var box=document.getElementById(name);
		 if(box.value=='搜索超过10万部影视内容'||searchTextTimer!=null){box.value=''};
		 stopSearchTextTimer();
		 G_USE_KANKAN_SEARCH=false;
	}catch(e){}
} 
function __set_default_se(){
	var default_se=getcooookie('xl7_d_se');
	if(default_se&&(default_se==1||default_se==2||default_se==3)){
		g_curre_se=default_se;
		try{
			$g('b_curr_se').className=G_SE[default_se].classname;
			$g('curr_se').title=G_SE[default_se].title;
			
			$g('zonghe_search').action=G_SE[default_se].action;
			$g("keyword").name=G_SE[default_se].kname;
			
			if(default_se=='1'){
				setSearchInputContent($g("keyword"));
				G_USE_KANKAN_SEARCH=true;
			}
			
		}catch(e){}		
	}
}
function hide_lab_list(e){
	e = e ? e : (window.event ? window.event : null);
	var e = e.target ? e.target : e.srcElement;
	if(e.id!='curr_se'&&e.id!='se_1'&&e.id!='se_2'&&e.id!='se_3'){
		$g('lab_list').style.display='none';
	}	
}
function getcooookie(name){
	var p=new RegExp('(^'+name+'|'+name+')=([^;]+)');
	var value=(document.cookie.match(p)==null)?'':RegExp.$2;
	return decodeURIComponent(value);
}
function setCookieWithDomain(name, value, hours,domain){
    var expire = "; path=/";
    if(hours != null) {
        expire = new Date((new Date()).getTime() + hours*3600000);
        expire = "; expires=" + expire.toGMTString() + "; path=/";
    }
    document.cookie = name + "=" + encodeURIComponent(value)+';domain='+domain +';'+ expire;
}
function $g(id){
	return document.getElementById(id);
}
var NONGLI={};
NONGLI.LunarDaysOfMonth = new Array(
	0xd4a8, 0xd4a0, 0xda50, 0x5aa8, 0x56a0, 0xaad8, 0x25d0, 0x92d0, 0xc958, 0xa950, // 2001-2010
	0xb4a0, 0xb550, 0xb550, 0x55a8, 0x4ba0, 0xa5b0, 0x52b8, 0x52b0, 0xa930, 0x74a8, // 2011-2020
	0x6aa0, 0xad50, 0x4da8, 0x4b60, 0x9570, 0xa4e0, 0xd260, 0xe930, 0xd530, 0x5aa0, // 2021-2030
	0x6b50, 0x96d0, 0x4ae8, 0x4ad0, 0xa4d0, 0xd258, 0xd250, 0xd520, 0xdaa0, 0xb5a0, // 2031-2040
	0x56d0, 0x4ad8, 0x49b0, 0xa4b8, 0xa4b0, 0xaa50, 0xb528, 0x6d20, 0xada0, 0x55b0 // 2041-2050
);
// 数组LunarLeapYear存放农历2001年到2050年闰月的月份，如没有则为0，从高到低，每字节存两年
NONGLI.LunarLeapYear = new Array(
	0x40, 0x02, 0x07, 0x00, 0x50, // 2001-2010
	0x04, 0x09, 0x00, 0x60, 0x04, // 2011-2020
	0x00, 0x20, 0x60, 0x05, 0x00, // 2021-2030
	0x30, 0xb0, 0x06, 0x00, 0x50, // 2031-2040
	0x02, 0x07, 0x00, 0x50, 0x03 // 2041-2050
);

// 返回农历iLunarYear年的闰月月份，如没有则返回0
NONGLI.GetLeapMonth=function(iLunarYear){
	var Leap = NONGLI.LunarLeapYear[(iLunarYear - 2001) >> 1];
	return (((iLunarYear - 2001) & 1) == 0) ? (Leap >> 4) : (Leap & 0x0f);
}

// 返回农历iLunarYer年iLunarMonth月的天数，结果是一个长整数
// 如果iLunarMonth不是闰月， 高字为0，低字为该月的天数
// 如果iLunarMonth是闰月， 高字为后一个月的天数，低字为前一个月的天数
NONGLI.LunarMonthDays=function(iLunarYear, iLunarMonth){
	var High;
	var Low;
	var Bit;

	High = 0;
	Low = 29;
	Bit = 16 - iLunarMonth;
	if ((iLunarMonth > NONGLI.GetLeapMonth(iLunarYear)) && (NONGLI.GetLeapMonth(iLunarYear) > 0)) Bit--;
	if ((NONGLI.LunarDaysOfMonth[iLunarYear - 2001] & (1 << Bit)) > 0) Low++;
	if (iLunarMonth == NONGLI.GetLeapMonth(iLunarYear))
	{
	High = ((NONGLI.LunarDaysOfMonth[iLunarYear - 2001] & (1 << (Bit-1))) > 0) ? 30 : 29;
	}

	return Low + (High << 16);
}

// 返回农历iLunarYear年的总天数
NONGLI.LunarYearDays=function(iLunarYear){
	var Days;
	var tmp;

	Days = 0;
	for (var i=1; i <= 12; i++)
	{
	tmp = NONGLI.LunarMonthDays(iLunarYear, i);
	Days = Days + ((tmp >> 16) & 0xffff); //取高位
	Days = Days + (tmp & 0xffff); //取低位
	}

	return Days;
}

// 将农历iLunarYear年格式化成天干地支记年法表示的字符串
NONGLI.FormatLunarYear=function(iLunarYear){
	var szText1 = new String("甲乙丙丁戊己庚辛壬癸");
	var szText2 = new String("子丑寅卯辰巳午未申酉戌亥");
	var strYear;

	strYear = szText1.substr((iLunarYear - 4) % 10, 1);
	strYear = strYear + szText2.substr((iLunarYear - 4) % 12, 1);

	return strYear + "年";
}

// 将农历iLunarMonth月格式化成农历表示的字符串
NONGLI.FormatLunarMonth=function(iLunarMonth){
	var szText = new String("正二三四五六七八九十");
	var strMonth;

	if (iLunarMonth <= 10)
	{
	strMonth = szText.substr(iLunarMonth - 1, 1);
	}
	else if (iLunarMonth == 11) strMonth = "十一";
	else strMonth = "十二";

	return strMonth + "月";
}

// 将农历iLunarDay日格式化成农历表示的字符串
NONGLI.FormatLunarDay=function(iLunarDay){
var szText1 = new String("初十廿三");
	var szText2 = new String("一二三四五六七八九十");
	var strDay;
	if((iLunarDay != 20)&&(iLunarDay != 30)){
		strDay = szText1.substr((iLunarDay - 1) / 10, 1) + szText2.substr((iLunarDay - 1) % 10, 1);
	}else if(iLunarDay != 20){
		strDay = szText1.substr(iLunarDay / 10, 1) + "十";
	}else{
		strDay = "二十";
	}
	return strDay;
}

// 将公历日期转换为农历日期，返回农历表示的字符串
NONGLI.GetLunarDateString=function(SolarDate){
	var tmp;
	var iLunarYear;
	var iLunarMonth;
	var iLunarDay;
	var Leap = false;
	var MinMilli = 1000 * 60;
	var HrMilli = MinMilli * 60;
	var DyMilli = HrMilli * 24;

	// 从2001年1月1日算起，给定的公历日期已经过去的天数
	// 11323是1970年1月1日到2001年1月1日之间的天数，因为Date是从1970年1月1日作为起点的
	var iSpanDays = Math.round(SolarDate.getTime()/DyMilli)-11323;

	// 公历2001年1月24日为农历2001年正月初一，差23天
	if (iSpanDays < 23){
		iYear = 2000;
		iLunarMonth = 12;
		iLunarDay = iSpanDays + 7;
	}else{
		// 从农历2001年正月初一算起
		iSpanDays = iSpanDays - 23;
		iLunarYear = 2001;
		iLunarMonth = 1;
		iLunarDay = 1;

		// 计算农历年
		tmp = NONGLI.LunarYearDays(iLunarYear);
		while (iSpanDays >= tmp)
		{
		iSpanDays -= tmp;
		iLunarYear++;
		tmp = NONGLI.LunarYearDays(iLunarYear);
		}

		// 计算农历月
		tmp =NONGLI.LunarMonthDays(iLunarYear, iLunarMonth) & 0xffff; //取低字
		while (iSpanDays >= tmp){
			iSpanDays -= tmp;
			if(iLunarMonth ==NONGLI.GetLeapMonth(iLunarYear)){ // 该年该月闰月
				tmp = NONGLI.LunarMonthDays(iLunarYear, iLunarMonth) >> 16; //取高字
				if (iSpanDays < tmp)
				{
				Leap = (tmp > 0) ? true : false; // 闰月的后个月？
				break;
				}
				iSpanDays = iSpanDays - tmp;
			}

			iLunarMonth++;
			tmp = NONGLI.LunarMonthDays(iLunarYear,iLunarMonth) & 0xffff; //取低字
		}

		// 计算农历日
		iLunarDay += iSpanDays;
	}

	//return NONGLI.FormatLunarYear(iLunarYear) + "&nbsp;" + (Leap ? "闰" : "") + NONGLI.FormatLunarMonth(iLunarMonth) + NONGLI.FormatLunarDay(iLunarDay);
	return NONGLI.FormatLunarMonth(iLunarMonth) + NONGLI.FormatLunarDay(iLunarDay);
}
var MYNAV={};
MYNAV.recordClick=function(obj){
	if(typeof(obj.href)=='undefined'||typeof(obj.title)=='undefined') return '';
	var href=obj.href;
	var title=obj.title;
	try{
		var linkviewed=getcooookie('linkviewed');
		if(linkviewed==''){
			setCookieWithDomain('linkviewed',href+'@@'+title,30*24,'123.xunlei.com');
		}else{
			var data=linkviewed.split('^^');
			var save_data=[];
			for(var i=0;i<data.length;i++){
				var link=data[i].split('@@');
				if(link[0]==href&&link[1]==title) continue;
				save_data.push(data[i]);
			}
			save_data.push(href+'@@'+title);
			var save_len=save_data.length;
			if(save_len>8){
				for(var jjjj=0;jjjj<(save_len-8);jjjj++){
					save_data.shift();
				}
			}
			setCookieWithDomain('linkviewed',save_data.join('^^'),30*24,'123.xunlei.com');
		}
	}catch(e){}
};
MYNAV.initClicked=function(){
	var linkviewed=getcooookie('linkviewed');
	if(linkviewed=='')return false;
	
	var data=linkviewed.split('^^');
	if(data.length==0) return false;
	
	var html='<h2>我最常用：</h2><ul>';
	var tmp_html='';
	for(var i=(data.length)-1;i>=0;i--){
		var link=data[i].split('@@');
		if(link[0]=='http://www.xunlei.com/'){
			tmp_html+='<li><a href="'+link[0]+'" title="'+link[1]+'"><strong class="c_hlight">'+link[1]+'</strong></a></li>';
		}else{
			tmp_html+='<li><a href="'+link[0]+'" title="'+link[1]+'">'+link[1]+'</a></li>';
		}		
	}
	if(tmp_html=='') return false;
	html+=tmp_html+'</ul>';	
	try{
		$g('often_clicked').innerHTML=html;
		$g('often_clicked').style.display='block';
	}catch(e){}
};
MYNAV.showNongli=function(){
	var d=new Date();
	var nongli=NONGLI.GetLunarDateString(d);
		
	var year=d.getFullYear();
	var weekday=d.getDay();
	var weeks=[];
	weeks[0]='周日';
	weeks[1]='周一';
	weeks[2]='周二';
	weeks[3]='周三';
	weeks[4]='周四';
	weeks[5]='周五';
	weeks[6]='周六';
	var month=(d.getMonth())+1;	
	var day=d.getDate();	
	var yangli=year+'年'+month+'月'+day+'日';
	try{
		$g('show_date_div').innerHTML=yangli+' '+weeks[weekday]+' <span>农历'+nongli+'</span>';
	}catch(e){}
};